﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;

namespace WebSys.UI.Control.ZhengShou
{
    public class Second_lawsuit_newControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox txtCaseid, txtSsh, txtYg, txtBg, txtDsr,
            txtSsdlr, txtAy, txtBz, txtID, txtFlag;
        MPCalendar txtCpddsj, txtKtsj, txtPjsj;
        DropDownList ddlSszt;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            string strid = base.Page.Request["ID"];
            string strcaseid = base.Page.Server.UrlDecode(base.Page.Request["caseid"]);
            if (string.IsNullOrEmpty(strcaseid))
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("案件号未填写！", "window.close();");
            }
            if (!base.Page.IsPostBack)
            {
                QSDATADLL();
                if (!string.IsNullOrEmpty(strcaseid)) { txtCaseid.Text = strcaseid; }
                if (string.IsNullOrEmpty(strid)) { txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); }
                else
                {
                    txtID.Text = strid;
                    EluZSProvider.ONEJUSTICE onejustice = _EluZSDataProvider.GetONEJUSTICE(strid);
                    txtCaseid.Text = onejustice.CASEID;
                    txtSsh.Text = onejustice.SSH;
                    txtYg.Text = onejustice.YG;
                    txtBg.Text = onejustice.BG;
                    txtDsr.Text = onejustice.DSR;

                    txtSsdlr.Text = onejustice.SSDLR;
                    txtAy.Text = onejustice.AY;
                    txtBz.Text = onejustice.BZ;

                    if (onejustice.CPDDSJ.HasValue) { txtCpddsj.Text = onejustice.CPDDSJ.Value.ToShortDateString(); }
                    if (onejustice.KTSJ.HasValue) { txtKtsj.Text = onejustice.KTSJ.Value.ToShortDateString(); }
                    if (onejustice.PJSJ.HasValue) { txtPjsj.Text = onejustice.PJSJ.Value.ToShortDateString(); }
                    ddlSszt.SelectedValue = onejustice.SSZT;
                }
            }

            Button btn_Insert = (Button)FindControl("btn_Insert");
            btn_Insert.Click += new EventHandler(btn_Insert_Click);
        }
        protected void InitControl()
        {
            txtCaseid = (TextBox)FindControl("txtCaseid");
            txtSsh = (TextBox)FindControl("txtSsh");
            txtYg = (TextBox)FindControl("txtYg");
            txtBg = (TextBox)FindControl("txtBg");
            txtDsr = (TextBox)FindControl("txtDsr");

            txtSsdlr = (TextBox)FindControl("txtSsdlr");
            txtAy = (TextBox)FindControl("txtAy");
            txtBz = (TextBox)FindControl("txtBz");
            txtID = (TextBox)FindControl("txtID");
            txtFlag = (TextBox)FindControl("txtFlag");

            txtCpddsj = (MPCalendar)FindControl("txtCpddsj");
            txtKtsj = (MPCalendar)FindControl("txtKtsj");
            txtPjsj = (MPCalendar)FindControl("txtPjsj");
            ddlSszt = (DropDownList)FindControl("ddlSszt");
        }
        protected void btn_Insert_Click(object sender, EventArgs e)
        {
            EluZSProvider.ONEJUSTICE onejustice = new EluZSProvider.ONEJUSTICE();
            string strid = base.Page.Request["ID"];
            onejustice.ID = txtID.Text;
            onejustice.CASEID = txtCaseid.Text;
            onejustice.SSH = txtSsh.Text.Trim();
            onejustice.YG = txtYg.Text.Trim();
            onejustice.BG = txtBg.Text.Trim();

            onejustice.DSR = txtDsr.Text.Trim();
            onejustice.SSDLR = txtSsdlr.Text.Trim();
            onejustice.AY = txtAy.Text.Trim();
            onejustice.BZ = txtBz.Text.Trim();
            onejustice.FLAG = txtFlag.Text.Trim();


            onejustice.CPDDSJ = (string.IsNullOrEmpty(txtCpddsj.Text) ? null : (DateTime?)Convert.ToDateTime(txtCpddsj.Text));
            onejustice.KTSJ = (string.IsNullOrEmpty(txtKtsj.Text) ? null : (DateTime?)Convert.ToDateTime(txtKtsj.Text));
            onejustice.PJSJ = (string.IsNullOrEmpty(txtPjsj.Text) ? null : (DateTime?)Convert.ToDateTime(txtPjsj.Text));
            onejustice.SSZT = ddlSszt.SelectedValue;

            base.Page.Session["nCount"] = "4";

            bool save = _EluZSDataProvider.SaveONEJUSTICE(strid, onejustice);

            Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptbasic1", "<script>windowClose('" + base.Page.Request["type"] + "');</script>");
        }
        protected void QSDATADLL()
        {
            List<EluZSProvider.Params> _params = _EluZSDataProvider.GetParams("诉讼状态");
            EluZSProvider.Params item = new EluZSProvider.Params();
            item.Keyname = "";
            item.Keyvalue = "0";
            _params.Insert(0, item);
            ddlSszt.DataSource = _params;
            ddlSszt.DataValueField = "keyvalue";
            ddlSszt.DataTextField = "keyname";
            ddlSszt.DataBind();
        }
    }
}


